package com.id.coinscleaner.junk

import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.lifecycle.lifecycleScope
import com.id.coinscleaner.R
import com.id.coinscleaner.common.ViewBindingFragment
import com.id.coinscleaner.databinding.FragmentJunkBoostBinding
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch


class JunkBoostFragment : ViewBindingFragment<FragmentJunkBoostBinding>() {
    override fun initView() {
        super.initView()
        if (arguments?.getString("finish_num") != null) {
            binding.readyCleanJunkNumTV.text = arguments?.getString("finish_num")
        }
        var progressNum = 0
        val finishNum = arguments?.getString("finish_num")
        val bundle = bundleOf("finish_num" to finishNum)
        lifecycleScope.launchWhenResumed {
            repeat(100) {
                delay(30)
                progressNum++
                if (progressNum <= 100)
                    binding.progressNumTV.text = "${progressNum}%"
            }
            progressNum = 0
            navigate(R.id.action_junkBoostFragment_to_junkFinishFragment, bundle)
        }
        binding.backIV.setOnClickListener {
            this.requireActivity().finish()
        }
    }
}